package com.javafamily;

import com.javafamily.balance.CRule;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class PetsConfigure {
    // 指定Ribbon使用随机算法策略
//    @Bean
//    public IRule RibbonBalanceRule(){
//        return new RandomRule();
//    }
    // 修改负载均衡策略为：自定义策略
    @Bean
    public IRule loadBalanceRule() {
        List<Integer> excludePorts = new ArrayList<>();
        // 只对8201、8202进行随机
        excludePorts.add(8203);
        return new CRule(excludePorts);
    }
}
